<?php
    use GatewayClient\Gateway;
    global $_W,$_GPC;
    $uniacid = $_W['uniacid'];
    $client_id = $_POST['client_id'];
    $rid = intval($_GPC['rid']);
    $reply = pdo_fetch( " SELECT * FROM ".tablename('haoman_dpm_countmoneyreply')." WHERE rid='".$rid."' " );
    $pici =empty($reply['pici'])?1:$reply['pici'];
    $c =100001;
  //  $from_user = $_W['fans']['from_user'];

    $user_agent = $_SERVER['HTTP_USER_AGENT'];
    if (strpos($user_agent, 'MicroMessenger') === false) {

        header("HTTP/1.1 301 Moved Permanently");
        header("Location: {$this->createMobileUrl('other',array('type'=>1,'id'=>$rid))}");
        exit();
    }

    $from_user = $_W['fans']['from_user'];
    $uniacid = $_W['uniacid'];
    load()->model('account');
    $_W['account'] = account_fetch($_W['acid']);
    $cookieid = '__cookie_haoman_dpm_201606186_' . $rid;
    $cookie = json_decode(base64_decode($_COOKIE[$cookieid]),true);
    if ($_W['account']['level'] != 4) {
        $from_user = $cookie['openid'];
    }
//    $from_user = 'oQAFAwCS19dHrsZhSd4h0uRdEKUM';
    $fans = pdo_fetch("select id,from_user,is_online from " . tablename('haoman_dpm_fans') . " where rid =:rid and from_user = :from_user ", array(':rid'=>$rid,':from_user' => $from_user));

    $uid = $from_user.$rid;

    $group = $rid;
    $group = $rid.$pici.$uniacid*$c;
// 用户已经登录，用户uid在session中
$message = $group;
Gateway::bindUid($client_id, $uid);

Gateway::joinGroup($client_id, $group);
Gateway::sendToGroup($group, json_encode($message));



